package Homework.game;

import java.util.Arrays;
import java.util.Scanner;

public class GetScoreAvg {

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入评委人数:");
        int personNum = sc.nextInt();
        double[] score=inputDaAta(personNum);
        double result = calAvg(score,personNum);
        System.out.printf("结果为:%.2f",result);

    }

    public static double[] inputDaAta(int perNum){
       double[] score = new double[perNum];
        Scanner sc = new Scanner(System.in);
        for (int i=0;i<perNum;i++){
            System.out.println("请输入第"+(i+1)+"个评委的分数:");
            score[i] = sc.nextInt();
        }
        System.out.println(Arrays.toString(score));
        return score;

    }

    public static double calAvg(double[] score,int perNum){
        double avg;
        double max=max(score);
        double min=min(score);
        double sum=0;
        for (int i=0;i<score.length;i++){
            sum+=score[i];
        }
        avg = (sum-max-min)/(perNum-2);
        return avg;
    }
    public static double max(double[] score){
        /*double max=score[0];
        for (int i=1;i<score.length;i++){
            if(score[i]>max){
                max=score[i];
            }
        }
        return max;
        */
        Arrays.sort(score);
        System.out.println("max:"+score[score.length-1]);
        return score[score.length-1];
    }
    public static double min(double[] score){
        /*double min=score[0];
        for (int i=1;i<score.length;i++){
            if(score[i]<min){
                min=score[i];
            }
        }
        return min;*/
        Arrays.sort(score);
        System.out.println("min:"+score[0]);
        return score[0];
    }
}
